import 'package:flutter/material.dart';
import 'package:portal_website/pages/common_header.dart';

class CreditServicePage extends StatelessWidget {
  const CreditServicePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xFFf5f9ff),
      body: SingleChildScrollView(
        child: Container(
          margin: EdgeInsets.only(top: 50),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Breadcrumb(text: "首页 > 服务能力 > 信用服务"),

              PageTitle(
                  title: "信用服务", subtitle: "专业信用评估与管理服务，助力企业建立良好信用形象，提升市场竞争力"),

              // 信用服务介绍
              _buildIntroSection(),

              // 服务内容
              _buildServicesSection(),

              // 评估流程
              _buildProcessSection(),

              // 信用价值
              _buildValueSection(),

              // 案例展示
              _buildCasesSection(),

              // 页脚
              _buildFooter(),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildHeader() {
    return Container(
      decoration: const BoxDecoration(
        gradient: LinearGradient(
          colors: [Color(0xFF1e5799), Color(0xFF207cca)],
          begin: Alignment.topLeft,
          end: Alignment.bottomRight,
        ),
        borderRadius: BorderRadius.all(Radius.circular(8)),
        boxShadow: [
          BoxShadow(
            color: Colors.black12,
            blurRadius: 5,
            spreadRadius: 2,
            offset: Offset(0, 5),
          ),
        ],
      ),
      padding: const EdgeInsets.symmetric(vertical: 30, horizontal: 30),
      margin: const EdgeInsets.only(bottom: 30),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          const Text(
            '创新服务平台',
            style: TextStyle(
              color: Colors.white,
              fontSize: 24,
              fontWeight: FontWeight.bold,
            ),
          ),
          LayoutBuilder(
            builder: (context, constraints) {
              if (constraints.maxWidth < 768) {
                return const SizedBox.shrink();
              }
              return _buildDesktopNavigation();
            },
          ),
        ],
      ),
    );
  }

  Widget _buildDesktopNavigation() {
    return Row(
      children: const [
        NavItem('首页'),
        NavItem('信用服务'),
        NavItem('信用评估'),
        NavItem('信用修复'),
        NavItem('联系我们'),
      ],
    );
  }

  Widget _buildIntroSection() {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: const BorderRadius.all(Radius.circular(8)),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.05),
            blurRadius: 3,
            spreadRadius: 1,
          ),
        ],
      ),
      padding: const EdgeInsets.all(40),
      margin: const EdgeInsets.only(bottom: 40),
      child: LayoutBuilder(
        builder: (context, constraints) {
          if (constraints.maxWidth < 768) {
            return Column(
              children: [
                _buildIntroText(),
                const SizedBox(height: 20),
                _buildIntroImage(),
              ],
            );
          }
          return Row(
            children: [
              Expanded(child: _buildIntroText()),
              const SizedBox(width: 40),
              _buildIntroImage(),
            ],
          );
        },
      ),
    );
  }

  Widget _buildIntroText() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: const [
        Text(
          '信用服务概述',
          style: TextStyle(
            color: Color(0xFF1e5799),
            fontSize: 24,
            fontWeight: FontWeight.bold,
          ),
        ),
        SizedBox(
          height: 20,
        ),
        Text(
          '在市场经济中，信用是企业最宝贵的无形资产之一。我们的信用服务团队由资深信用管理专家组成，拥有丰富的行业经验和成功案例。我们采用科学的信用评估模型，结合大数据分析技术，为企业提供全方位的信用服务。',
          style: TextStyle(
            color: Color(0xFF555555),
            fontSize: 16,
            height: 1.8,
          ),
        ),
        SizedBox(
          height: 20,
        ),
        Text(
          '服务内容包括企业信用评估、信用报告、信用监测、信用修复和信用管理等。我们已为超过1000家企业提供了专业信用服务，帮助客户提升信用等级，降低融资成本，增强市场竞争力。',
          style: TextStyle(
            color: Color(0xFF555555),
            fontSize: 16,
            height: 1.8,
          ),
        ),
        SizedBox(
          height: 20,
        ),
        Text(
          '我们的信用评估体系已获得多家金融机构和行业协会的认可，评估结果可作为企业融资、投标和市场拓展的重要参考依据。',
          style: TextStyle(
            color: Color(0xFF555555),
            fontSize: 16,
            height: 1.8,
          ),
        ),
      ],
    );
  }

  Widget _buildIntroImage() {
    return Container(
      width: 500,
      height: 300,
      decoration: BoxDecoration(
        borderRadius: const BorderRadius.all(Radius.circular(8)),
        image: const DecorationImage(
          image: NetworkImage(''),
          fit: BoxFit.cover,
        ),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.1),
            blurRadius: 5,
            spreadRadius: 2,
            offset: const Offset(0, 5),
          ),
        ],
      ),
    );
  }

  Widget _buildServicesSection() {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: const BorderRadius.all(Radius.circular(8)),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.05),
            blurRadius: 3,
            spreadRadius: 1,
          ),
        ],
      ),
      padding: const EdgeInsets.all(40),
      margin: const EdgeInsets.only(bottom: 40),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          _buildSectionTitle('服务内容'),
          const SizedBox(height: 10),
          const Text(
            '全方位的信用服务，满足企业不同阶段的信用需求',
            style: TextStyle(
              color: Color(0xFF666666),
              fontSize: 16,
            ),
          ),
          const SizedBox(height: 30),
          _buildServicesGrid(),
        ],
      ),
    );
  }

  Widget _buildSectionTitle(String title) {
    return Container(
      padding: const EdgeInsets.only(bottom: 15),
      decoration: const BoxDecoration(
        border: Border(
          bottom: BorderSide(
            color: Color(0xFFf0f0f0),
            width: 2,
          ),
        ),
      ),
      child: Stack(
        children: [
          Text(
            title,
            style: const TextStyle(
              color: Color(0xFF1e5799),
              fontSize: 24,
              fontWeight: FontWeight.bold,
            ),
          ),
          Positioned(
            bottom: -2,
            left: 0,
            child: Container(
              width: 80,
              height: 2,
              color: const Color(0xFF207cca),
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildServicesGrid() {
    return GridView.count(
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(),
      crossAxisCount: 3,
      crossAxisSpacing: 30,
      mainAxisSpacing: 30,
      childAspectRatio: 350 / 350,
      children: const [
        ServiceCard(
          icon: '📊',
          title: '企业信用评估',
          description: '基于企业财务数据、经营状况、行业地位等多维度信息，提供专业信用评级服务，全面反映企业信用状况。',
        ),
        ServiceCard(
          icon: '📝',
          title: '信用报告服务',
          description: '提供标准版和定制版企业信用报告，包含企业基本信息、财务数据、信用评级、风险提示等内容。',
        ),
        ServiceCard(
          icon: '🔍',
          title: '信用监测预警',
          description: '实时监测企业信用状况变化，及时发现潜在风险，提供预警服务，帮助企业防范信用风险。',
        ),
        ServiceCard(
          icon: '🔄',
          title: '信用修复服务',
          description: '针对存在信用问题的企业，提供专业的信用修复方案，帮助企业改善信用状况，重建市场信任。',
        ),
        ServiceCard(
          icon: '📈',
          title: '信用管理咨询',
          description: '提供信用管理体系建设、信用政策制定、应收账款管理等咨询服务，提升企业信用管理水平。',
        ),
        ServiceCard(
          icon: '🎓',
          title: '信用管理培训',
          description: '开展信用管理专业培训，提升企业员工信用风险意识和信用管理能力，培养专业信用管理人才。',
        ),
      ],
    );
  }

  Widget _buildProcessSection() {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: const BorderRadius.all(Radius.circular(8)),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.05),
            blurRadius: 3,
            spreadRadius: 1,
          ),
        ],
      ),
      padding: const EdgeInsets.all(40),
      margin: const EdgeInsets.only(bottom: 40),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          _buildSectionTitle('信用评估流程'),
          const SizedBox(height: 10),
          const Text(
            '科学严谨的评估流程，确保信用评估结果的客观公正',
            style: TextStyle(
              color: Color(0xFF666666),
              fontSize: 16,
            ),
          ),
          const SizedBox(height: 40),
          LayoutBuilder(
            builder: (context, constraints) {
              if (constraints.maxWidth < 768) {
                return _buildMobileProcessSteps();
              }
              return _buildDesktopProcessSteps();
            },
          ),
        ],
      ),
    );
  }

  Widget _buildDesktopProcessSteps() {
    return Stack(
      children: [
        Positioned(
          top: 30,
          left: 0,
          right: 0,
          height: 3,
          child: Container(
            decoration: const BoxDecoration(
              gradient: LinearGradient(
                colors: [Color(0xFF207cca), Color(0xFF1e5799)],
              ),
            ),
          ),
        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: const [
            ProcessStep(
              number: '1',
              title: '资料收集',
              description: '收集企业基本信息、财务数据、经营状况等资料',
            ),
            ProcessStep(
              number: '2',
              title: '实地考察',
              description: '对企业进行实地考察，核实资料真实性',
            ),
            ProcessStep(
              number: '3',
              title: '数据分析',
              description: '运用信用评估模型对数据进行分析',
            ),
            ProcessStep(
              number: '4',
              title: '初步评级',
              description: '形成初步信用评级结果',
            ),
            ProcessStep(
              number: '5',
              title: '报告发布',
              description: '出具正式信用评估报告',
            ),
          ],
        ),
      ],
    );
  }

  Widget _buildMobileProcessSteps() {
    return Column(
      children: const [
        ProcessStepMobile(
          number: '1',
          title: '资料收集',
          description: '收集企业基本信息、财务数据、经营状况等资料',
        ),
        ProcessStepMobile(
          number: '2',
          title: '实地考察',
          description: '对企业进行实地考察，核实资料真实性',
        ),
        ProcessStepMobile(
          number: '3',
          title: '数据分析',
          description: '运用信用评估模型对数据进行分析',
        ),
        ProcessStepMobile(
          number: '4',
          title: '初步评级',
          description: '形成初步信用评级结果',
        ),
        ProcessStepMobile(
          number: '5',
          title: '报告发布',
          description: '出具正式信用评估报告',
        ),
      ],
    );
  }

  Widget _buildValueSection() {
    return Container(
      decoration: const BoxDecoration(
        gradient: LinearGradient(
          colors: [Color(0xFF1e5799), Color(0xFF207cca)],
          begin: Alignment.topLeft,
          end: Alignment.bottomRight,
        ),
        borderRadius: BorderRadius.all(Radius.circular(8)),
      ),
      padding: const EdgeInsets.symmetric(vertical: 60, horizontal: 40),
      margin: const EdgeInsets.only(bottom: 40),
      child: Column(
        children: [
          const Text(
            '良好信用的价值',
            style: TextStyle(
              color: Colors.white,
              fontSize: 28,
              fontWeight: FontWeight.bold,
            ),
          ),
          const SizedBox(height: 40),
          GridView.count(
            shrinkWrap: true,
            physics: const NeverScrollableScrollPhysics(),
            crossAxisCount: 4,
            crossAxisSpacing: 30,
            mainAxisSpacing: 30,
            childAspectRatio: 250 / 260,
            children: const [
              ValueItem(
                icon: '💰',
                title: '降低融资成本',
                description: '良好信用可帮助企业获得更低利率的融资，降低资金成本',
              ),
              ValueItem(
                icon: '🤝',
                title: '增强商业合作',
                description: '提升合作伙伴信任度，拓展商业机会',
              ),
              ValueItem(
                icon: '📈',
                title: '提升市场竞争力',
                description: '在招投标、政府采购等场景中获得优势',
              ),
              ValueItem(
                icon: '🛡️',
                title: '防范信用风险',
                description: '及时发现和解决信用问题，避免重大损失',
              ),
            ],
          ),
        ],
      ),
    );
  }

  Widget _buildCasesSection() {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: const BorderRadius.all(Radius.circular(8)),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.05),
            blurRadius: 3,
            spreadRadius: 1,
          ),
        ],
      ),
      padding: const EdgeInsets.all(40),
      margin: const EdgeInsets.only(bottom: 40),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          _buildSectionTitle('成功案例'),
          const SizedBox(height: 10),
          const Text(
            '我们已为众多企业提供了专业的信用服务',
            style: TextStyle(
              color: Color(0xFF666666),
              fontSize: 16,
            ),
          ),
          const SizedBox(height: 30),
          GridView.count(
            shrinkWrap: true,
            physics: const NeverScrollableScrollPhysics(),
            crossAxisCount: 3,
            crossAxisSpacing: 30,
            mainAxisSpacing: 30,
            childAspectRatio: 300 / 320,
            children: const [
              CaseCard(
                imageUrl: 'https://via.placeholder.com/400x200?text=制造企业',
                title: '某制造企业信用修复',
                description: '帮助该企业修复信用问题，6个月内信用评级提升2个等级，成功获得银行贷款。',
              ),
              CaseCard(
                imageUrl: 'https://via.placeholder.com/400x200?text=科技企业',
                title: '科技企业信用评估',
                description: '为该科技企业提供信用评估服务，评估结果助力企业获得风险投资。',
              ),
              CaseCard(
                imageUrl: 'https://via.placeholder.com/400x200?text=贸易公司',
                title: '贸易公司信用管理',
                description: '帮助贸易公司建立信用管理体系，应收账款逾期率下降60%。',
              ),
            ],
          ),
        ],
      ),
    );
  }

  Widget _buildFooter() {
    return Container(
      decoration: const BoxDecoration(
        color: Color(0xFF1a1a2e),
        borderRadius: BorderRadius.all(Radius.circular(8)),
      ),
      padding: const EdgeInsets.all(40),
      margin: const EdgeInsets.only(top: 50),
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: const [
              FooterLink('关于我们'),
              SizedBox(width: 40),
              FooterLink('服务条款'),
              SizedBox(width: 40),
              FooterLink('隐私政策'),
              SizedBox(width: 40),
              FooterLink('帮助中心'),
              SizedBox(width: 40),
              FooterLink('联系我们'),
            ],
          ),
          const SizedBox(height: 20),
          const Text(
            '© 2025 创新服务平台 版权所有',
            style: TextStyle(
              color: Colors.white,
              fontSize: 14,
            ),
          ),
          const SizedBox(height: 10),
          const Text(
            '地址：XX省XX市XX区XX路XX号 | 服务热线：400-123-4567 | 邮箱：credit@innovationservice.com',
            style: TextStyle(
              color: Colors.white,
              fontSize: 14,
            ),
          ),
        ],
      ),
    );
  }
}

// 导航项组件
class NavItem extends StatelessWidget {
  final String text;

  const NavItem(this.text, {super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(left: 25),
      child: Text(
        text,
        style: const TextStyle(
          color: Colors.white,
          fontSize: 16,
        ),
      ),
    );
  }
}

// 服务卡片组件
class ServiceCard extends StatelessWidget {
  final String icon;
  final String title;
  final String description;

  const ServiceCard({
    super.key,
    required this.icon,
    required this.title,
    required this.description,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: const Color(0xFFf9fbff),
        borderRadius: const BorderRadius.all(Radius.circular(8)),
        border: Border.all(
          color: const Color(0xFFe0e9ff),
          width: 1,
        ),
      ),
      padding: const EdgeInsets.all(30),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            icon,
            style: const TextStyle(fontSize: 48, color: Color(0xFF207cca)),
          ),
          const SizedBox(height: 20),
          Text(
            title,
            style: const TextStyle(
              color: Color(0xFF1e5799),
              fontSize: 20,
              fontWeight: FontWeight.bold,
            ),
          ),
          const SizedBox(height: 15),
          Text(
            description,
            style: const TextStyle(
              color: Color(0xFF666666),
              fontSize: 15,
              height: 1.7,
            ),
          ),
          const SizedBox(height: 20),
          Container(
            padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
            decoration: const BoxDecoration(
              color: Color(0xFF1e5799),
              borderRadius: BorderRadius.all(Radius.circular(4)),
            ),
            child: const Text(
              '了解详情',
              style: TextStyle(
                color: Colors.white,
                fontSize: 14,
              ),
            ),
          ),
        ],
      ),
    );
  }
}

// 流程步骤组件（桌面版）
class ProcessStep extends StatelessWidget {
  final String number;
  final String title;
  final String description;

  const ProcessStep({
    super.key,
    required this.number,
    required this.title,
    required this.description,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 150,
      child: Column(
        children: [
          Container(
            width: 60,
            height: 60,
            decoration: BoxDecoration(
              color: const Color(0xFF207cca),
              borderRadius: const BorderRadius.all(Radius.circular(30)),
              boxShadow: [
                BoxShadow(
                  color: const Color(0xFF1e5799).withOpacity(0.3),
                  blurRadius: 5,
                  spreadRadius: 2,
                  offset: const Offset(0, 5),
                ),
              ],
            ),
            child: Center(
              child: Text(
                number,
                style: const TextStyle(
                  color: Colors.white,
                  fontSize: 24,
                  fontWeight: FontWeight.bold,
                ),
              ),
            ),
          ),
          const SizedBox(height: 15),
          Text(
            title,
            style: const TextStyle(
              color: Color(0xFF1e5799),
              fontSize: 16,
              fontWeight: FontWeight.bold,
            ),
          ),
          const SizedBox(height: 10),
          Text(
            description,
            textAlign: TextAlign.center,
            style: const TextStyle(
              color: Color(0xFF666666),
              fontSize: 14,
            ),
          ),
        ],
      ),
    );
  }
}

// 流程步骤组件（移动版）
class ProcessStepMobile extends StatelessWidget {
  final String number;
  final String title;
  final String description;

  const ProcessStepMobile({
    super.key,
    required this.number,
    required this.title,
    required this.description,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(bottom: 30),
      child: Row(
        children: [
          Container(
            width: 60,
            height: 60,
            margin: const EdgeInsets.only(right: 20),
            decoration: BoxDecoration(
              color: const Color(0xFF207cca),
              borderRadius: const BorderRadius.all(Radius.circular(30)),
              boxShadow: [
                BoxShadow(
                  color: const Color(0xFF1e5799).withOpacity(0.3),
                  blurRadius: 5,
                  spreadRadius: 2,
                  offset: const Offset(0, 5),
                ),
              ],
            ),
            child: Center(
              child: Text(
                number,
                style: const TextStyle(
                  color: Colors.white,
                  fontSize: 24,
                  fontWeight: FontWeight.bold,
                ),
              ),
            ),
          ),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  title,
                  style: const TextStyle(
                    color: Color(0xFF1e5799),
                    fontSize: 16,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                const SizedBox(height: 10),
                Text(
                  description,
                  style: const TextStyle(
                    color: Color(0xFF666666),
                    fontSize: 14,
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

// 价值项组件
class ValueItem extends StatelessWidget {
  final String icon;
  final String title;
  final String description;

  const ValueItem({
    super.key,
    required this.icon,
    required this.title,
    required this.description,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white.withOpacity(0.1),
        borderRadius: const BorderRadius.all(Radius.circular(8)),
      ),
      padding: const EdgeInsets.all(30),
      child: Column(
        children: [
          Text(
            icon,
            style: const TextStyle(fontSize: 40, color: Colors.white),
          ),
          const SizedBox(height: 20),
          Text(
            title,
            style: const TextStyle(
              color: Colors.white,
              fontSize: 20,
              fontWeight: FontWeight.bold,
            ),
          ),
          const SizedBox(height: 15),
          Text(
            description,
            textAlign: TextAlign.center,
            style: const TextStyle(
              color: Colors.white,
              fontSize: 14,
              // opacity: 0.9,
            ),
          ),
        ],
      ),
    );
  }
}

// 案例卡片组件
class CaseCard extends StatelessWidget {
  final String imageUrl;
  final String title;
  final String description;

  const CaseCard({
    super.key,
    required this.imageUrl,
    required this.title,
    required this.description,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        borderRadius: const BorderRadius.all(Radius.circular(8)),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.1),
            blurRadius: 5,
            spreadRadius: 2,
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            height: 200,
            decoration: BoxDecoration(
              image: DecorationImage(
                image: NetworkImage(imageUrl),
                fit: BoxFit.cover,
              ),
              borderRadius: const BorderRadius.vertical(
                top: Radius.circular(8),
              ),
            ),
          ),
          Container(
            padding: const EdgeInsets.all(20),
            color: Colors.white,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  title,
                  style: const TextStyle(
                    color: Color(0xFF1e5799),
                    fontSize: 18,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                const SizedBox(height: 10),
                Text(
                  description,
                  style: const TextStyle(
                    color: Color(0xFF666666),
                    fontSize: 14,
                  ),
                ),
                const SizedBox(height: 15),
                const Text(
                  '查看详情 →',
                  style: TextStyle(
                    color: Color(0xFF207cca),
                    fontSize: 14,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

// 页脚链接组件
class FooterLink extends StatelessWidget {
  final String text;

  const FooterLink(this.text, {super.key});

  @override
  Widget build(BuildContext context) {
    return Text(
      text,
      style: const TextStyle(
        color: Color(0xFFa8b2d1),
        fontSize: 14,
      ),
    );
  }
}
